{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>添加区/县</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">选择省/市</label>
            <div class="layui-input-inline">
                <select name="" lay-verify="required" lay-filter="province">
                    <option value="">请选择省</option>
					{volist name="province" id="province"}
						<option value="{$province.id}">{$province.name}</option>
					{/volist}
                </select>
            </div>
            <div class="layui-input-inline" >
                <select name="pid" lay-verify="required" id="pid">
                    <option value="">请选择市</option>
                </select>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">区/县名称</label>
            <div class="layui-input-4">
                <input type="text" name="name" 
				lay-verify="required"
				maxlength="10"
				placeholder="请输入区/县名称" 
				class="layui-input"/>
			</div>
		</div>	
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" id="submit" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery;
            form.on('select(province)', function(data){
                var pid = data.value;
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.get("{:url('getRegion')}?pid=" + pid, function (data) {
                    layer.close(loading);
                    var html='<option value="">请选择市</option>';
                    $.each(data, function (i, value) {
                        html += '<option value="number:'+value.id+'">'+value.name+'</option>';
                    });
                    $('#pid').html(html);
                    form.render()
                });
            });
            form.on('submit(submit)', function (data) {
                $("#submit").attr({ disabled: "disabled" });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.errorCode == 8888) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
						$("#submit").removeAttr("disabled");
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })
        });
   
</script>
</body>
</html>